#!/usr/bin/env bash

ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd )"

active_pid=

main() {
  set -e

  pushd "$ROOT" &> /dev/null
    go install ./cmd/dfuseeos
  popd &> /dev/null

  if [[ $KILL_AFTER != "" ]]; then
    ${GOPATH:-$HOME/go}/bin/dfuseeos "$@" &
    active_pid=$!

    sleep $KILL_AFTER
    kill -s TERM $active_pid &> /dev/null || true
  else
    exec ${GOPATH:-$HOME/go}/bin/dfuseeos "$@"
  fi
}

main "$@"